<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function getArray(arr) {
            const o = {}
            for (let i = 0; i < arr.length; i++) {
                if (o[arr[i]]) {
                    o[arr[i]]++
                } else {
                    o[arr[i]] = 1
                }
            }
            let max = 0
            let index = 0
            for (let k in o) {
                console.log(o[k])
                if (o[k] > max) {
                    max = o[k]
                    index = k
                }
            }
            console.log(`${index} 最多，共有${max}次}`)
        }
        const arr = [1, 2, 2, 1, 3, 1, 1]
        getArray(arr)
    </script>
</body>

</html>